package com.graduate.controller;

import com.graduate.po.*;
import com.graduate.service.PaymentService;
import com.graduate.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * Created by lx on 2021/3/4.
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {
    @Resource(name = "paymentServiceImpl")
    private PaymentService paymentService;
    @Resource(name = "userServiceImpl")
    private UserService userService;
    // 用户主页
    @RequestMapping(value = "index")
    public String index(Model model, HttpServletRequest request) throws Exception {
        return "user/index";
    }

    // 显示缴费历史
    @RequestMapping(value = "/payList")
    public String payList(Model model, Integer page, HttpServletRequest request) throws Exception {
        Subject subject = SecurityUtils.getSubject();
        User user = (User)subject.getPrincipal();
        List<PaymentCustom> list = null;
        //页码对象
        PagingVO pagingVO = new PagingVO();
        //设置总页数
        pagingVO.setTotalCount(paymentService.getPaymentCountByUserID(user.getUserID()));
        if (page == null || page == 0) {
            pagingVO.setToPageNo(1);
            list = paymentService.findByPagingEachByID(user.getUserID(), 1);
        } else {
            pagingVO.setToPageNo(page);
            list = paymentService.findByPagingEachByID(user.getUserID(), page);
        }
        model.addAttribute("userFeeList", list);
        model.addAttribute("pagingVO", pagingVO);
        model.addAttribute("curUserID", user.getUserID());
        return "user/payList";
    }
    // 在线缴费
    @RequestMapping(value = "/payOnline")
    public String payOnline(Model model) throws Exception {
        return "user/payOnline";
    }
    //修改密码
    @RequestMapping(value = "/passwordRest")
    public String passwordRest() throws Exception {
        return "user/passwordRest";
    }
}
